package com.xb.ConnectionPool_C3p0;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;

import java.sql.Connection;

public class ConnectionPool_C3p0Test {
    @Test
    public void test() throws Exception{
        ComboPooledDataSource cpds = new ComboPooledDataSource();
        cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver
        cpds.setJdbcUrl( "jdbc:mysql://localhost:3306/test" );
        cpds.setUser("root");
        cpds.setPassword("123");
        //设置最大的Statement数
        cpds.setMaxStatements( 180 );
        //设置数据库池最大连接时间
        cpds.setMaxConnectionAge(100);
        //设置数据库连接最小池数
        cpds.setMinPoolSize(10);
        cpds.setMaxPoolSize(150);
        Connection connection = cpds.getConnection();
        System.out.println(connection); //com.mchange.v2.c3p0.impl.NewProxyConnection@21bcffb5
    }
    @Test
    public void test02() throws Exception{
        ComboPooledDataSource cpds = new ComboPooledDataSource("helloC3p0");
        Connection connection = cpds.getConnection();
        System.out.println(connection); //com.mchange.v2.c3p0.impl.NewProxyConnection@38082d64
    }
}
